#ifndef WIDGET_H
#define WIDGET_H

#include <map>

#include "Entity.h"
#include "Flag.h"
#include "OString.h"
#include "Texture.h"
#include "Poly.h"

namespace Y{

class Compositor;

class Widget: public Entity{
	
	
	public:
		Flag acceptedEvents;
		Flag_64 drawingFlags;
			static std::map < OString, long > drawingFlagMap;
		
		//Drawing data
		Vertex3f	position;
		Vertex2f	dimensions;
		Vertex4f	color;
		Texture *	texture;
		
		static Compositor * compositor;
		
		
	public:
		
		Widget ();
		Widget (Widget *w);
		virtual ~Widget ();
			void _WidgetInit ();
		
		//Configuring Functions
		virtual void handleConfig	( ConfigVector& cv );
		void setDrawingFlag			(int,bool);
		bool hasDrawingFlag			(int);
		//Drawing Functions
		void drawingSubsystem			(Compositor *);
		virtual void preDraw				(Compositor *);
		virtual void drawBackground	();
		virtual void postDraw			();
		
		ClippingPoly getClippingPoly ();
		//Event Functions
		virtual bool mousePress		(float x, float y);
		virtual bool mouseRelease	(float x, float y);
		virtual bool mouseMove		(float x, float y);
		virtual bool mouseDrag		(float x, float y);
		virtual bool mouseEnter		();
		virtual bool mouseExit		();
		virtual bool scrollWheel	(float dx,float dy,float dz); 
		virtual bool keyPress		(unsigned char c, int mod);
		virtual bool keyRelease		(unsigned char c, int mod);
			void eventSubsystem		(int);
			void eventSubsystem		(float,float,int);
			void eventSubsystem		(float,float,float,int);
			void eventSubsystem		(unsigned char,int,int);
			
		bool acceptsEvent			(int e);
		void setAcceptsEvent		(int e,bool b);
		
		Widget * parent(){ return (Widget*)parent_entity; }
		
		
		//Drawing functions
			//Drawing State changes
			void pushMatrix();void popMatrix();
			void translate (float,float,float);
//			void rotate	   (float,float,float,float);
			
			void pushColor ();void popColor ();
			void multColor (const Vertex4f& c);
			void setColor  (const Vertex4f& c);
			
			void setTexture (Texture *t);
			//Primitive changing primitives
			void drawQuad (float x,float y,float w,float h);
				inline void drawQuad ( const Vertex2i& v, float w, float h ){ drawQuad( v.x(),v.y(),w,h ); }
			void drawPoly (Vertex2f v[], int n);
		
};

}

#endif